package com.yiyi.credit.manage.sso.manager.controller;


import com.yiyi.credit.manage.sso.common.page.Pagination;
import com.yiyi.credit.manage.sso.model.dto.response.Response;
import com.yiyi.credit.manage.sso.model.entity.SysUserRole;
import com.yiyi.credit.manage.sso.service.inner.SysUserRoleService;
import com.yiyi.credit.manage.sso.service.outter.SseSystemClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class SysUserRoleController {

    //private static Logger logger = LoggerFactory.getLogger(SysUserRoleController.class);

    @Autowired
    SysUserRoleService sysUserRoleService;

    @Autowired
    SseSystemClient sseSystemClient;


    @RequestMapping(value = "/getSysUserRolePageList")
    public Object getSysUserRolePageList(@RequestParam Long sysInfoId, String userName,
                                         @RequestParam Integer pageIndex, @RequestParam Integer pageSize) throws Exception {

        Pagination pagination = new Pagination(pageIndex, pageSize);
        Pagination result = sysUserRoleService.getSysUserRolePageBySysId(sysInfoId, userName, pagination);
        return new Response<>(result);
    }

    //
    // @RequestMapping(value = "/addSysUserRole")
    // public Object addSysUserRole(Long sysInfoId,Long userId,Long roleId,Long subStationId) throws Exception {
    //
    //     SysUserRole sysUserRole =new SysUserRole();
    //     sysUserRole.setSysInfoId(sysInfoId);
    //     sysUserRole.setUserId(userId);
    //     sysUserRole.setRoleId(roleId);
    //     sysUserRole.setSubStationId(subStationId);
    //     sysUserRoleService.addSysUserRole(sysUserRole);
    //     return new Response<>();
    // }


    @RequestMapping(value = "/addSysUserRole")
    public Object addSysUserRole(@RequestBody SysUserRole sysUserRole) throws Exception {

        sysUserRoleService.addSysUserRole(sysUserRole);
        return new Response<>();
    }


    @RequestMapping(value = "/updateSysUserRole")
    public Object updateSysUserRole(@RequestBody SysUserRole sysUserRole) throws Exception {

        sysUserRoleService.updateSysUserRole(sysUserRole);
        return new Response<>();
    }


    @RequestMapping(value = "/batchAddSysUserRole")
    public Object batchAddSysUserRole(@RequestParam String userIds, @RequestParam Long sysInfoId,
                                      @RequestParam Long roleId) throws Exception {

        sysUserRoleService.batchAssignSysUserRole(userIds, sysInfoId, roleId);
        return new Response<>();
    }




    @RequestMapping("/getSubStationList")
    public Object getSubStationList() {

        return sseSystemClient.getSubStationList();
    }



}
